package com.onlineproject.util;
	import java.util.*;
	import javax.mail.*;
	import javax.mail.internet.*;
	public class SendEmail {
		public static boolean sendEmailToActivate(String aimAdderess, String path, String activateCode, String usertype) {
			try {
			String from = "wdzhangqing2011@163.com";
			String to = aimAdderess + "@whu.edu.cn";
			String subject = "激活链接";
			String messageText = "<a href='" + path + "loginRegisterAction!activateStudentOrTeacher?activateCode="+activateCode+"&email="+aimAdderess+"&usertype="+usertype+"'" + " target='_top'" + ">请点击激活</a>";
			System.out.println(messageText);
			String password = "877514131xin5088";
			String mailserver = "smtp.163.com";
			Properties prop = new Properties();
			prop.put("mail.smtp.host", mailserver);
			prop.put("mail.smtp.auth", "true");
			Session sess = Session.getInstance(prop);
			sess.setDebug(true);
			MimeMessage message = new MimeMessage(sess);
			// 给消息对象设置收件人、发件人、主题、发信时间
			InternetAddress mail_from = new InternetAddress(from);
			message.setFrom(mail_from);
			InternetAddress mail_to = new InternetAddress(to);
			message.setRecipient(Message.RecipientType.TO, mail_to);
			message.setSubject(subject);
			message.setSentDate(new Date());
	
			Multipart mul = new MimeMultipart(); // 新建一个MimeMultipart对象来存放多个BodyPart对象
			BodyPart mdp = new MimeBodyPart(); // 新建一个存放信件内容的BodyPart对象
			mdp.setContent(messageText, "text/html;charset=gb2312");
			mul.addBodyPart(mdp); // 将含有信件内容的BodyPart加入到MimeMulitipart对象中
			message.setContent(mul); // 把mul作为消息对象的内容
			message.saveChanges();
			Transport transport = sess.getTransport("smtp");
			// 以smtp方式登陆邮箱，第1个参数是发送邮件用的邮件服务器SMTP地址，第2个参数为用户名，第3个参数为密码
			transport.connect(mailserver, from, password);
			transport.sendMessage(message, message.getAllRecipients());
			transport.close();
			System.out.println("发送邮件成功");
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("发送邮件产生的错误：" + e.getMessage());
			return false;
		}
			return true;
		}
	
		public static boolean sendEmailToRemand(String aimAdderess) {
			try {
			String from = "wdzhangqing2011@163.com";
			String to = aimAdderess + "@whu.edu.cn";
			String subject = "提醒关注";
			String messageText = "你的项目接近截止期，请关注";
			System.out.println(messageText);
			String password = "877514131xin5088";
			String mailserver = "smtp.163.com";
			Properties prop = new Properties();
			prop.put("mail.smtp.host", mailserver);
		prop.put("mail.smtp.auth", "true");
			Session sess = Session.getInstance(prop);
			sess.setDebug(true);
			MimeMessage message = new MimeMessage(sess);
			// 给消息对象设置收件人、发件人、主题、发信时间
			InternetAddress mail_from = new InternetAddress(from);
			message.setFrom(mail_from);
			InternetAddress mail_to = new InternetAddress(to);
			message.setRecipient(Message.RecipientType.TO, mail_to);
			message.setSubject(subject);
			message.setSentDate(new Date());
	
			Multipart mul = new MimeMultipart(); // 新建一个MimeMultipart对象来存放多个BodyPart对象
			BodyPart mdp = new MimeBodyPart(); // 新建一个存放信件内容的BodyPart对象
			mdp.setContent(messageText, "text/html;charset=gb2312");
			mul.addBodyPart(mdp); // 将含有信件内容的BodyPart加入到MimeMulitipart对象中
			message.setContent(mul); // 把mul作为消息对象的内容
			message.saveChanges();
			Transport transport = sess.getTransport("smtp");
			// 以smtp方式登陆邮箱，第1个参数是发送邮件用的邮件服务器SMTP地址，第2个参数为用户名，第3个参数为密码
			transport.connect(mailserver, from, password);
			transport.sendMessage(message, message.getAllRecipients());
			transport.close();
			System.out.println("发送邮件成功");
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("发送邮件产生的错误：" + e.getMessage());
			return false;
		}
			return true;
		}
}